m4_dnl Copyright (C) 2018 Alister Sanders
m4_dnl
m4_dnl This program is free software: you can redistribute it and/or modify
m4_dnl it under the terms of the GNU General Public License as published by
m4_dnl the Free Software Foundation, either version 3 of the License, or
m4_dnl (at your option) any later version.
m4_dnl
m4_dnl This program is distributed in the hope that it will be useful,
m4_dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
m4_dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
m4_dnl GNU General Public License for more details.
m4_dnl
m4_dnl You should have received a copy of the GNU General Public License
m4_dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
m4_dnl
m4_divert(-1)m4_dnl

# `sp_defn' is defined with a preceeding newline so that macros defined
# with it can be used in single line comments in configurations
m4_define(`sp_def', `m4_define(`$1', `$2')m4_dnl')

sp_def(`sp_defn', `sp_def(`$1', `
$2')m4_dnl')

sp_def(`sp_default', `ifdef(`$1', `', `sp_def(`$1', `$2')')')
sp_default(`SP_DATETIME',   m4_esyscmd(echo -n $(date "+%F %T")))
sp_default(`SP_VERSION',    `<unknown version>')
sp_default(`SP_BUILDHOST',  `<unknown build host>')
sp_default(`SP_TARGETHOST', `<unknown target host>')

sp_defn(sp_blurb, `sp_com Generated with spotfile SP_VERSION on SP_DATETIME
sp_com Build Host  : SP_BUILDHOST
sp_com Target Host : SP_TARGETHOST')

sp_defn(sp_use,       `sp_com --- begin spotfile content ($1) ---
m4_include($1)sp_com --- end spotfile content ($1)---')

sp_defn(sp_maybe_use, `sp_com --- begin spotfile content ($1) ---
m4_sinclude($1)
sp_com --- end spotfile content ($1)---')

# Use host-specific files
sp_def(`sp_host_use',       `sp_use(SP_TARGETHOST/$1)')
sp_def(`sp_host_maybe_use', `sp_maybe_use(SP_TARGETHOST/$1)')

# Set the default single-line comment marker to `#'
sp_def(`sp_set_com', `sp_def(`sp_com', `$1')')
sp_set_com(`#')

# Finally, disable m4 comments so that macros can be expanded within
# configuration comments
m4_changecom(`')

m4_divert(0)m4_dnl
